package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.elder.business.domain.ApartmentRoomPrice;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.business.domain.ApartmentRoomInfo;
import com.elder.business.service.IApartmentRoomInfoService;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 公寓房间信息Controller
 * 
 * @author elder
 * @date 2023-11-26
 */
@RestController
public class ApartmentRoomInfoController extends BaseController
{
    @Autowired
    private IApartmentRoomInfoService apartmentRoomInfoService;

    /**
     * 查询公寓房间信息列表
     */
    @Anonymous
    @GetMapping("/business/roomInfo/list")
    public TableDataInfo list(Long apartmentId, Integer roomType, Integer roomStutas, Integer pageNum, Integer pageSize)
    {
        JSONArray list = apartmentRoomInfoService.selectApartmentRoomInfoList(apartmentId, roomType, roomStutas, pageNum, pageSize);
        return getDataTable(list);
    }

    @Anonymous
    @RequestMapping("/business/roomInfo/getRoomInfoList")
    public TableDataInfo getList(){
        return apartmentRoomInfoService.getRoomInfo();
    }
    /**
     * 导出公寓房间信息列表
     */
//    @PreAuthorize("@ss.hasPermi('business:roomInfo:export')")
//    @Log(title = "公寓房间信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ApartmentRoomInfo apartmentRoomInfo)
//    {
//        List<ApartmentRoomInfo> list = apartmentRoomInfoService.selectApartmentRoomInfoList(apartmentRoomInfo);
//        ExcelUtil<ApartmentRoomInfo> util = new ExcelUtil<ApartmentRoomInfo>(ApartmentRoomInfo.class);
//        util.exportExcel(response, list, "公寓房间信息数据");
//    }

    /**
     * 获取公寓房间信息详细信息
     */
    @Anonymous
    @GetMapping("/business/roomInfo/getRoomInfoById")
    public AjaxResult getInfo(@RequestParam("id") Long id)
    {
        return success(apartmentRoomInfoService.selectApartmentRoomInfoById(id));
    }

    /**
     * 新增公寓房间信息
     */
    @Anonymous
    @Log(title = "公寓房间信息", businessType = BusinessType.INSERT)
    @PostMapping("/business/roomInfo")
    public AjaxResult add(@RequestBody ApartmentRoomInfo apartmentRoomInfo)
    {
        return toAjax(apartmentRoomInfoService.insertApartmentRoomInfo(apartmentRoomInfo));
    }

    /**
     * 修改公寓房间信息
     */
    @Anonymous
    @Log(title = "公寓房间信息", businessType = BusinessType.UPDATE)
    @PutMapping("/business/roomInfo")
    public AjaxResult edit(@RequestBody ApartmentRoomInfo apartmentRoomInfo)
    {
        return toAjax(apartmentRoomInfoService.updateApartmentRoomInfo(apartmentRoomInfo));
    }

    /**
     * 删除公寓房间信息
     */
    @Anonymous
    @Log(title = "公寓房间信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/business/roomInfo/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(apartmentRoomInfoService.deleteApartmentRoomInfoByIds(ids));
    }

    /***
     * @description 房间床位信息 可根据公寓 房间状态 类型查询
     * @param apartmentId
     * @param roomType
     * @param pageNum
     * @param pageSize
     * @return String
     * @author zyk
     * @date 2023/12/7 10:33
     */
    @Anonymous
    @RequestMapping("/business/roomInfo/roomBedInfo")
    public String getElderRoomBedInfo(Long apartmentId, Integer roomType, Integer roomStatus,Integer pageNum,Integer pageSize){
        return JSON.toJSONString(apartmentRoomInfoService.getElderRoomBedInfo(apartmentId,roomType, roomStatus, pageNum, pageSize));
    }

    @Anonymous
    @RequestMapping("/business/roomInfo/nurseRoom")
    public TableDataInfo getNurseRoomInfo(){
        return apartmentRoomInfoService.getNurseRoomInfo();
    }
    /***
     * @description 获取房间最新定价
     * @return String
     * @author zyk
     * @date 2023/12/23 10:14
     */
    @Anonymous
    @RequestMapping("/business/roomInfo/roomNewPrice")
    public TableDataInfo getNewRoomPriceInfo(){
        return apartmentRoomInfoService.getRoomNewPriceInfo();
    }

    /***
     * @description  获取公寓房间定价
     * @param createTime
     * @param applyStatus
     * @return TableDataInfo
     * @author zyk
     * @date 2023/12/11 20:29
     */
    @Anonymous
    @RequestMapping("/business/roomInfo/roomPriceInfo")
    public TableDataInfo getApartmentRoomPriceList(Long createTime,String applyStatus){
        return apartmentRoomInfoService.getApartmentRoomPriceList(createTime,applyStatus);
    }

    /***
     * @description 修改房间定价信息
     * @param
     * @return AjaxResult
     * @author zyk
     * @date 2023/12/11 20:31
     */
    @Anonymous
    @RequestMapping("/business/roomInfo/updateRoomPrice")
    public AjaxResult updateRoomPrice(@NotNull Long roomPriceId, String roomRemark, String roomPrice, String nurseContent, String applyStatus){
        return apartmentRoomInfoService.updateRoomPriceInfo(roomPriceId,roomRemark,roomPrice,nurseContent,applyStatus);
    }

    @Anonymous
    @RequestMapping("/business/roomInfo/addRoomPrice")
    public AjaxResult addRoomPrice(ApartmentRoomPrice apartmentRoomPrice){
        return apartmentRoomInfoService.addRoomPriceInfo(apartmentRoomPrice);
    }

}
